﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApFLEXFrameSelection
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApFLEXFrameSelection : ICApFLEXFrameSelection
{
  private readonly FrameSelectionType m_frameSelectionType;
  private readonly IEnumerable<FrameSelectionType> m_frameSelectionTypesToCheck;
  private readonly ICApCableFrameStatus m_frameStatus;

  public CApFLEXFrameSelection(
    FrameSelectionType frameSelectionType,
    ICApCableFrameStatus frameStatus)
  {
    this.m_frameSelectionType = frameSelectionType;
    this.m_frameStatus = frameStatus ?? throw new ArgumentNullException("attributeViewModel");
    this.m_frameSelectionTypesToCheck = this.ComputeFrameSelectionTypesToCheck();
  }

  public bool IsFrameAlreadyUsed(
    ITxLocatableObject locatableObject,
    out FrameSelectionType frameSelectionType)
  {
    frameSelectionType = this.m_frameStatus.ComputeAlreadyDefinedFrameSelectionType(locatableObject, this.m_frameSelectionTypesToCheck);
    return frameSelectionType != 0;
  }

  public bool IsFrameScopeValid(ITxLocatableObject locatableObject)
  {
    return this.m_frameSelectionType != FrameSelectionType.PassNearFrame && this.m_frameSelectionType != FrameSelectionType.AttachmentFrame || this.m_frameStatus.IsFrameWithinSameScopeAsCable(locatableObject);
  }

  private IEnumerable<FrameSelectionType> ComputeFrameSelectionTypesToCheck()
  {
    ICollection<FrameSelectionType> selectionTypesToCheck = (ICollection<FrameSelectionType>) new List<FrameSelectionType>();
    foreach (FrameSelectionType frameSelectionType in Enum.GetValues(typeof (FrameSelectionType)))
    {
      if (frameSelectionType != FrameSelectionType.None && frameSelectionType != this.m_frameSelectionType)
        selectionTypesToCheck.Add(frameSelectionType);
    }
    return (IEnumerable<FrameSelectionType>) selectionTypesToCheck;
  }
}
